package com.xdf.xzymanagementsystem.controller;

import com.xdf.xzymanagementsystem.entity.SysUser;
import com.xdf.xzymanagementsystem.service.SysParamsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Api(tags = "系统参数")
@CrossOrigin
@RestController
@RequestMapping("/sysParams")
public class SysParamsController {
    @Autowired
    private SysParamsService sysParamsService;

    // 获取当前登录系统的用户对象
    @GetMapping("/getCurrentUser")
    public SysUser getCurrentUser(){
        return sysParamsService.getLoginUser();
    }

    @GetMapping("/getUserName")
    public Map<String,String> getUserName(){
        Map<String,String> ret = new HashMap<>();
        String userName = Optional.ofNullable(sysParamsService.getUserName()).orElse("");
        ret.put("userName",userName);
        return ret;
    }
}
